<?php

function jobHandle($str){
	$kycfg = get_kycfg(LID);
	$pattern = "/([a-z]+)([0-9]+)/";
	preg_match($pattern,$str,$match);

	$ret = $kycfg[$match[1]];
	return $ret[$match[2]];
}
function ret_video($arr){
	$tmp = explode('.',$arr['src']);
	$sfx = $tmp[count($tmp)-1];
	$str = '';
	if(is_Mobile()){
		$str.='<div id="videoview"></div>'."\r\n";
		$str.='<script type="text/javascript" src="/run_plug/ckplayer/ckplayer.js" charset="utf-8"></script>'."\r\n";
		$str.='<script type="text/javascript">'."\r\n";
		$str.='var flashvars={'."\r\n";
		$str.='p:0,'."\r\n";
		$str.='e:1,'."\r\n";
		$str.='i:"'.$arr['img'].'"'."\r\n";
		$str.='};'."\r\n";
		$str.='var video=["'.$arr['src'].'->video/mp4"];'."\r\n";
		$str.='var support=["all"];'."\r\n";
		$str.='CKobject.embedHTML5("videoview","ckplayer_a1","100%","",video,flashvars,support);'."\r\n";
		$str.='</script>'."\r\n";
	}else{
		$str.='<div id="videoview"></div>'."\r\n";
		$str.='<script type="text/javascript" src="/run_plug/ckplayer/ckplayer.js" charset="utf-8"></script>'."\r\n";
		$str.='<script type="text/javascript">'."\r\n";
		$str.='var flashvars={'."\r\n";
		$str.='f:"'.$arr['src'].'",'."\r\n";
		$str.='c:0,'."\r\n";
		$str.='b:1,'."\r\n";
		$str.='i:"'.$arr['img'].'"'."\r\n";
		$str.='};'."\r\n";
		$str.='var params={bgcolor:"#FFF",allowFullScreen:true,allowScriptAccess:"always",wmode:"transparent"};'."\r\n";
		$str.='CKobject.embedSWF("/run_plug/ckplayer/ckplayer.swf","videoview","ckplayer_a1","600","400",flashvars,params);	'."\r\n";
		$str.='</script>'."\r\n";
	}
	return $str;
}


//内容详情视频替换
function replace_video($body){
$pattern = "/<p><iframe\ssrc=\"([a-z0-9:.\/]+)\"\s+width=\"(\d+)\"\s+height=\"(\d+)\" scrolling=\"yes\" frameborder=\"0\" align=\"\"><\/iframe><\/p>/";
	if(preg_match_all($pattern, $body,$match)){
		for($i=0;$i<count($match[0]);$i++){
			$tmp = "<style>#video{$i}{width:{$match[2][$i]}px;height:{$match[3][$i]}px;}</style>\r\n"; 
			$tmp.= "<div id='video{$i}'></div>\r\n";
			$video = explode('.',$match[1][$i]);
			if($video[count($video)-1]=='mp4'){
				$tmp.= "<script type='text/javascript'>\r\n";
				$tmp.= "var flashvars={\r\n";
				$tmp.= "	p:0,\r\n";
				$tmp.= "	e:1,\r\n";
				$tmp.= "	i:'http://www.ckplayer.com/static/images/cqdw.jpg'\r\n";
				$tmp.= "	};\r\n";
				$tmp.= "var video=['http://img.ksbbs.com/asset/Mon_1605/0ec8cc80112a2d6.mp4->video/mp4'];\r\n";
				$tmp.= "var support=['all'];\r\n";
				$tmp.= "CKobject.embedHTML5('video{$i}','ckplayer_video1','100%','100%',video,flashvars,support);\r\n";
				$tmp.= "</script>\r\n";
			}else{
				$tmp.= "<script type='text/javascript'>\r\n";
				$tmp.= "	var flashvars={\r\n";
				$tmp.= "		f:'{$match[1][$i]}',\r\n";
				$tmp.= "		c:0,\r\n";
				$tmp.= "		b:1,\r\n";
				$tmp.= "		};\r\n";
				$tmp.= "	var params={bgcolor:'#FFF',allowFullScreen:true,";
				$tmp.= "allowScriptAccess:'always',wmode:'transparent'};\r\n";
				$tmp.= "	CKobject.embedSWF('/run_plug/ckplayer/ckplayer.swf','video{$i}',";
				$tmp.= "'ckplayer_a1','100%','100%',flashvars,params);\r\n";
				$tmp.= "</script>\r\n";
			}
			$body= str_replace($match[0][$i],$tmp,$body);
		}
	}
	$return = "<script type='text/javascript' src='/run_plug/ckplayer/ckplayer.js' charset='utf-8'></script>\r\n".$body;
	return $return;
}

function checkauth($auth,$title,$desc,$sf){
	$str = <<<EOF
<table width="100%" border="1" cellpadding="3" cellspacing="1" bgcolor="#DDEAC8">
   <tbody>
   	<tr bgcolor="#EFF4EA">
     <td height="48" colspan="2" align="center"><b>提示信息</b></td>
   	</tr>
   	<tr bgcolor="#FFFFFF">
     <td height="60" colspan="2" align="center">
     	本页需要 <font color="red">{$auth}</font> 以上的权限才能访问，你目前身份是：<font color="red">{$sf}</font> ！     </td>
   	</tr>
   	<tr bgcolor="#EFF4EA">
      <th width="10%" height="35" align="center">标题</th>
      <td width="90%" height="35">{$title}</td>
   	</tr>
    <tr bgcolor="#FFFFFF">
       <th height="70" align="center">简介</th>
       <td>{$desc}</td>
    </tr>
  </tbody></table>
EOF;
return $str;
}

function recommednav($navt,$orgnav,$id){
	$arr = $navt::getRecommend($orgnav,$id);
	$str="";
	if($arr){
		foreach($arr as $v){
			$str.="<a href='/goods_{$v["id"]}.html'>{$v['navname']}</a>\r\n";
		}
	}
	return $str;
}

function hotnav($navt,$orgnav,$id){
	$arr = $navt::getHot($orgnav,$id);
	$str="";
	if($arr){
		foreach($arr as $v){
			$str.="<a href='/goods_{$v["id"]}.html' class='hotnav'>{$v['navname']}</a>\r\n";
		}
	}
	return $str;
}


function returl($id){
	return "/goods_".$id.".html";
}

//当前栏目所属类型下设置为检索的规格项
function searchspec($nav){
	$sfield = [];
	$where['typeid'] = ['eq',$nav['typeid']];
	$where['issearch'] = ['eq',1];
	$sarr = think\Db::name('goodsspec')->field('id,impactprice')->where($where)->select();

	foreach($sarr as $k=>$v){
		$sfield['id'][] = $v['id'];
		$sfield['impact'][]  = $v['impactprice'];
	}
	return $sfield;
}

function picarr($pics){
	$str = '';
	$arr = explode("#",$pics);
	array_pop($arr);
	if($arr){
		foreach($arr as $v){
			$str.= '<div class="item">'."\r\n";
			$str.= '<img src="'.$v.'"/>'."\r\n";
			$str.= '</div>'."\r\n";  
		}
	}
	return $str;
}